//
//  QForgetPassWordCell.m
//  QoilPublic
//
//  Created by 杨凯 on 16/7/4.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QForgetPassWordCell.h"

@interface QForgetPassWordCell()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@property (weak, nonatomic) IBOutlet UITextField *phoneTextField;

@property (weak, nonatomic) IBOutlet UIButton *getAuthCode;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *fieldConstr;

@end
@implementation QForgetPassWordCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setSeparatorInset:UIEdgeInsetsZero];
    [self setLayoutMargins:UIEdgeInsetsZero];
    [self.phoneTextField addTarget:self action:@selector(textAction:) forControlEvents:UIControlEventEditingChanged];
    _phoneTextField.delegate = self;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [textField resignFirstResponder];
    return YES;
}

- (void)setupAttbuild:(NSIndexPath *)indexPath{
    
    if(indexPath.section == 0 && indexPath.row == 0){
        _titleLabel.text = @"手机号";
        _phoneTextField.placeholder = @"请输入手机号码";
        _phoneTextField.tag = 1;
        _phoneTextField.keyboardType = UIKeyboardTypeNumberPad;
        _phoneTextField.clearButtonMode = UITextFieldViewModeAlways;
        _getAuthCode.hidden = YES;
        if(iphone5x_4_0){
            _fieldConstr.constant = 230;
        }else{
            _fieldConstr.constant = 280;
        }
        
    }else if (indexPath.section == 0 && indexPath.row == 1){
    
        _titleLabel.text = @"验证码";
        _phoneTextField.placeholder = @"输入验证码";
        _phoneTextField.tag = 2;
        _phoneTextField.keyboardType = UIKeyboardTypeNumberPad;
        _phoneTextField.clearButtonMode = UITextFieldViewModeNever;
        _getAuthCode.hidden = NO;
        if(iphone5x_4_0){
            _fieldConstr.constant = 130;
        }else{
            _fieldConstr.constant = 150;
        }

    }else{
        _titleLabel.text = @"新密码";
        _phoneTextField.secureTextEntry = YES;
        _phoneTextField.placeholder = @"请输入新密码";
        _phoneTextField.tag = 3;
        _phoneTextField.keyboardType = UIKeyboardTypeDefault;
        _phoneTextField.clearButtonMode = UITextFieldViewModeNever;
        _getAuthCode.hidden = YES;
        if(iphone5x_4_0){
            _fieldConstr.constant = 230;
        }else{
            _fieldConstr.constant = 280;
        }
    }
}


- (IBAction)getAuthCodeAction:(id)sender {
    if(self.codeBlock){
        self.codeBlock(_getAuthCode);
    }
}

- (void)textAction:(UITextField *)textField{
    if(self.block){
        self.block(textField);
    }
}



@end
